import {defineConfig, loadEnv} from "vite"
import vue from "@vitejs/plugin-vue"

const path = require("path")

// https://vitejs.dev/config/
export default ({mode}) => defineConfig({
    plugins: [vue()],
    resolve: {
        alias: {
            "@": path.resolve(__dirname, "src"),
        },
        extensions: [".js", ".ts", ".tsx", ".jsx"],

    },
    base: "./", // 打包路径
    css: {
        // 配置全局样式
        preprocessorOptions: {
            scss: {
                charset: false,
                // additionalData: `@import "@/assets/styles/common.scss";`,
            },
        },
        postcss: {
            plugins: [
                require("postcss-import"),
                require("tailwindcss"),
                require("autoprefixer"),
                // 去除 @charset 警告
                {
                    postcssPlugin: "internal:charset-removal",
                    AtRule: {
                        charset: (atRule) => {
                            if (atRule.name === "charset") {
                                atRule.remove()
                            }
                        },
                    },
                },
            ],
        },
    },
    server: {
        host: "0.0.0.0",
        https: false,
        port: 3000, // 启动端口
        open: true,
        proxy: {
            "/admin": { //这个名字与 http.ts 中的 baseURL 一定要一致，切记！
                target: loadEnv(mode, process.cwd()).VITE_BASE_URL,
                changeOrigin: true,
            },
        },
    },
    build: {
        // 生产环境移除 console
        terserOptions: {
            compress: {
                drop_console: true,
                drop_debugger: true,
            },
        },
    },
})
